package com.gl.framework.security;

import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gl.portal.system.vo.SysUserVo;

/**
 * 登录用户信息对象
 */
public class LoginUser implements UserDetails {
	private static final long serialVersionUID = 1L;

	/**
	 * 用户唯一标识
	 */
	private String token;

	/**
	 * 登陆时间
	 */
	private Long loginTime;

	/**
	 * 过期时间
	 */
	private Long expireTime;

	/**
	 * 登录IP地址
	 */
	private String ipaddr;

	/**
	 * 登录地点
	 */
	private String loginLocation;

	/**
	 * 浏览器类型
	 */
	private String browser;

	/**
	 * 操作系统
	 */
	private String os;

	/**
	 * 菜单权限标识列表
	 */
	private Set<String> permissions;

	/**
	 * 角色ID组
	 */
	private List<Long> roleIds;

	/**
	 * 角色权限字符串列表
	 */
	private Set<String> roleKeys;

	/**
	 * 部门数据权限列表
	 */
	private List<Long> dataScopes;

	/**
	 * 用户信息VO
	 */
	private SysUserVo user;

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public LoginUser() {
	}

	public LoginUser(SysUserVo user, List<Long> roleIds, Set<String> roleKeys, List<Long> dataScopes, Set<String> permissions) {
		this.user = user;
		this.roleIds = roleIds;
		this.roleKeys = roleKeys;
		this.dataScopes = dataScopes;
		this.permissions = permissions;
	}

	@JsonIgnore
	@Override
	public String getPassword() {
		return user.getPassword();
	}

	@JsonIgnore
	@Override
	public String getUsername() {
		return user.getLoginName();
	}

	/**
	 * 账户是否未过期,过期无法验证
	 */
	@JsonIgnore
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	/**
	 * 指定用户是否解锁,锁定的用户无法进行身份验证
	 *
	 * @return
	 */
	@JsonIgnore
	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	/**
	 * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
	 *
	 * @return
	 */
	@JsonIgnore
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	/**
	 * 是否可用 ,禁用的用户不能身份验证
	 *
	 * @return
	 */
	@JsonIgnore
	@Override
	public boolean isEnabled() {
		return true;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return null;
	}

	public Long getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(Long loginTime) {
		this.loginTime = loginTime;
	}

	public Long getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(Long expireTime) {
		this.expireTime = expireTime;
	}

	public String getIpaddr() {
		return ipaddr;
	}

	public void setIpaddr(String ipaddr) {
		this.ipaddr = ipaddr;
	}

	public String getLoginLocation() {
		return loginLocation;
	}

	public void setLoginLocation(String loginLocation) {
		this.loginLocation = loginLocation;
	}

	public String getBrowser() {
		return browser;
	}

	public void setBrowser(String browser) {
		this.browser = browser;
	}

	public String getOs() {
		return os;
	}

	public void setOs(String os) {
		this.os = os;
	}

	public Set<String> getPermissions() {
		return permissions;
	}

	public void setPermissions(Set<String> permissions) {
		this.permissions = permissions;
	}

	public List<Long> getRoleIds() {
		return roleIds;
	}

	public void setRoleIds(List<Long> roleIds) {
		this.roleIds = roleIds;
	}

	public Set<String> getRoleKeys() {
		return roleKeys;
	}

	public void setRoleKeys(Set<String> roleKeys) {
		this.roleKeys = roleKeys;
	}

	public List<Long> getDataScopes() {
		return dataScopes;
	}

	public void setDataScopes(List<Long> dataScopes) {
		this.dataScopes = dataScopes;
	}

	public SysUserVo getUser() {
		return user;
	}

	public void setUser(SysUserVo user) {
		this.user = user;
	}

}
